package au.edu.unsw.editingtool.db;

import java.sql.SQLException;
import java.util.ArrayList;

public class DBSysconstant extends DBManager {

	protected void setupDBMapping() {
		if (MappingTable.size() > 0)
			return;
		MappingTable.put("GCID", "gcid");
		MappingTable.put("Label", "label");
		MappingTable.put("GCType", "gctype");
		MappingTable.put("Note", "note");		
	}
	
	public DBSysconstant() {
		this.table = "sysconstant";
		// Set primary
		this.primaryKeys = new String[]{""};
		// Setup the mapping
		this.setupDBMapping();
	}
	
	public ArrayList<String> getLabel(String gcid)throws ClassNotFoundException, SQLException	
	{
		ArrayList<String> label= new ArrayList<String>();
		String fields[] = {"Label","GCType"};
		this.setTable(this.table, "");
		this.setFieldsCondition("GCID", this.setEqual(gcid));
		this.addField(fields);	
		
		this.initDB();
		this.selectRecords();
		if (this.ResultSet == null) {
			System.out.println("[DBSysconstant] getLabel Resultset = NULL");
			this.clean();
			return label;
		}
				
		int count = 0;
		while(ResultSet.next())
		{
			count ++;
			label.add(ResultSet.getObject(1).toString());
			label.add(ResultSet.getObject(2).toString());
		}
		
		if (count==1)
		{
			System.out.println("[DBSysconstant] getLabel Resultset = 1");
			this.clean();
			return label;
		}
		else
		{
			this.clean();
			return null;	
		}				
	}
}
